//Copyright 2017 Sashihara Shisyu.All Rights Reserved.
#pragma once

#include "Factories/Factory.h"
#include "Editor/UnrealEd/Public/SkelImport.h"

#include "PmxFile.h"

#include "MMDPmxFactory.generated.h"

UCLASS()
class UMMDPmxFactory :public UFactory {
	GENERATED_UCLASS_BODY()

public:
	virtual UObject* FactoryCreateFile(UClass* InClass, UObject* InParent, FName InName, EObjectFlags Flages, const FString& Filename, const TCHAR* Parms, FFeedbackContext* Warn, bool& bOutOperationCanceled) override;

private:
	bool CheckSetting();
	bool FillSkeletaMeshImportData(FPMXFormat PmxData, FSkeletalMeshImportData* OutData);
	bool ImportTextures(FPMXFormat PmxData, FString PmxFile, FString rootPkgName, bool& bImportWasCancelled);
	UTexture2D* ImportTexture(FString path, FString pkgName, bool& bImportWasCancelled, FString fileListName, int32 FileID);
	bool ImportMaterials(FPMXFormat PmxData, FString rootPkgName,FString PmxFile);
	UMaterialInstanceConstant* ImportMaterial(FString pkg, FPMXFormatMaterialData materialData, int32 matID);
	UTexture* GetIDTexture(int32 ID);

private:
	TArray<TPair<FString, UTexture2D*>> Textures;
	TArray<UMaterialInstanceConstant*> Materials;
};